# Copyright (c) 2024 Huawei Technologies Co., Ltd.
# This file is a part of the CANN Open Software.
# Licensed under CANN Open Software License Agreement Version 1.0 (the "License").
# Please refer to the License for details. You may not use this file except in compliance with the License.
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
# See LICENSE in the root of the software repository for the full text of the License.
# ======================================================================================================================

project(ascendc_tests)
cmake_minimum_required(VERSION 3.16.0)

get_filename_component(ASCENDC_TESTS_DIR "${CMAKE_CURRENT_SOURCE_DIR}" ABSOLUTE)

set(PRODUCT_TYPE_LIST ascend610 ascend310p ascend910B1_AIC ascend910B1_AIV ascend310B1)
add_compile_definitions(__CCE_KT_TEST__=1 ASCENDC_CPU_DEBUG=1 ASCENDC_DUMP=0 LOG_CPP)

if(BUILD_OPEN_PROJECT)
    include(cmake/config.cmake)
    include(cmake/intf.cmake)
    include(cmake/func.cmake)
endif()

set(ASCENDC_SYS_DIR ${ASCEND_CANN_PACKAGE_PATH}/${CMAKE_SYSTEM_PROCESSOR}-linux)

set(ASCENDC_DEP_HEADER_DIR
    ${ASCENDC_SYS_DIR}/include
    ${ASCENDC_SYS_DIR}/include/base
    ${ASCENDC_SYS_DIR}/include/tiling
    ${ASCEND_CANN_PACKAGE_PATH}/tools/tikicpulib/lib/include
)

set(ASCEND_DEP_LIB_DIR
    ${ASCENDC_SYS_DIR}/lib64/
    ${ASCEND_CANN_PACKAGE_PATH}/tools/tikicpulib/lib/
)

set(CMAKE_CXX_STANDARD 17)

set(ASCENDC_TEST_HEADER_FILES
    ${ASCENDC_TESTS_DIR}/common
    ${ASCENDC_TESTS_DIR}/matmul/utils
    ${ASCENDC_API_DIR}
    ${KERNEL_TILING_DIR}
    ${ASCENDC_SYS_DIR}/tikcpp/tikcfw
    ${ASCENDC_SYS_DIR}/tikcpp/tikcfw/interface
    ${ASCENDC_SYS_DIR}/tikcpp/tikcfw/impl
)

# ascend610 test cases
file(GLOB ASCENDC_TEST_ascend610_CASE_SRC_FILES
    ${ASCENDC_TESTS_DIR}/activation/sigmoid/test_operator_vec_sigmoid.cpp
    ${ASCENDC_TESTS_DIR}/pad/broadcast/test_operator_broadcast_v200.cpp
    ${ASCENDC_TESTS_DIR}/math/erf/test_operator_erf.cpp
    ${ASCENDC_TESTS_DIR}/math/erfc/test_operator_erfc.cpp
    ${ASCENDC_TESTS_DIR}/math/round/test_operator_round.cpp
    ${ASCENDC_TESTS_DIR}/quantization/antiquant/test_ascend_quant.cpp
    ${ASCENDC_TESTS_DIR}/quantization/antiquant/test_ascend_quant_per_channel.cpp
)

# ascend310p test cases
file(GLOB ASCENDC_TEST_ascend310p_CASE_SRC_FILES
    ${ASCENDC_TESTS_DIR}/activation/sigmoid/test_operator_vec_sigmoid.cpp
    ${ASCENDC_TESTS_DIR}/quantization/antiquant/test_ascend_quant.cpp
    ${ASCENDC_TESTS_DIR}/quantization/antiquant/test_ascend_quant_per_channel.cpp
    # ${ASCENDC_TESTS_DIR}/quantization/dequant/test_operator_dequant_v200.cpp
    ${ASCENDC_TESTS_DIR}/matmul/test_matmul_config.cpp
    ${ASCENDC_TESTS_DIR}/matmul/copy_cube_in/test_copy_cube_in_mdl_310p.cpp
    ${ASCENDC_TESTS_DIR}/matmul/copy_cube_in/test_copy_cube_in_norm_310p.cpp
    ${ASCENDC_TESTS_DIR}/matmul/test_operator_matmul_v200.cpp
    ${ASCENDC_TESTS_DIR}/normalization/normalize/test_operator_normalize.cpp
    ${ASCENDC_TESTS_DIR}/normalization/welfordfinalize/test_operator_welfordfinalize.cpp
    ${ASCENDC_TESTS_DIR}/normalization/welfordupdate/test_operator_welfordupdate.cpp
    ${ASCENDC_TESTS_DIR}/matmul/scheduler/bias_scheduler/test_bias_scheduler_v200.cpp
    ${ASCENDC_TESTS_DIR}/matmul/scheduler/batch_scheduler/test_batch_scheduler_v200.cpp
    ${ASCENDC_TESTS_DIR}/normalization/layernormV2/test_operator_layernormV2.cpp
    ${ASCENDC_TESTS_DIR}/matmul/scheduler/test_scheduler_norm.cpp
)

# ascend910B1 aiv test cases
file(GLOB ASCENDC_TEST_ascend910B1_AIV_CASE_SRC_FILES
    ${ASCENDC_TESTS_DIR}/activation/geglu/test_operator_geglu.cpp
    ${ASCENDC_TESTS_DIR}/activation/gelu/test_operator_fast_gelu.cpp
    ${ASCENDC_TESTS_DIR}/activation/gelu/test_operator_fast_gelu_v2.cpp
    ${ASCENDC_TESTS_DIR}/activation/reglu/test_operator_reglu.cpp
    ${ASCENDC_TESTS_DIR}/activation/sigmoid/test_operator_vec_sigmoid.cpp
    ${ASCENDC_TESTS_DIR}/activation/silu/test_operator_silu.cpp
    ${ASCENDC_TESTS_DIR}/activation/softmax/test_operator_softmax_v220.cpp
    ${ASCENDC_TESTS_DIR}/activation/softmax/test_operator_softmaxflashv3_v220.cpp
    ${ASCENDC_TESTS_DIR}/activation/swiglu/test_operator_swiglu.cpp
    ${ASCENDC_TESTS_DIR}/activation/swish/test_operator_swish.cpp
    ${ASCENDC_TESTS_DIR}/reduce/mean/test_operator_mean.cpp
    ${ASCENDC_TESTS_DIR}/reduce/sum/test_operator_sum.cpp
    ${ASCENDC_TESTS_DIR}/reduce/reduce_prod/test_operator_reduce_prod.cpp
    ${ASCENDC_TESTS_DIR}/reduce/reduce_max/test_operator_reduce_max.cpp
    ${ASCENDC_TESTS_DIR}/reduce/reduce_min/test_operator_reduce_min.cpp
    ${ASCENDC_TESTS_DIR}/reduce/reduce_any/test_operator_reduce_any.cpp
    ${ASCENDC_TESTS_DIR}/reduce/reduce_all/test_operator_reduce_all.cpp
    ${ASCENDC_TESTS_DIR}/reduce/reduce_sum/test_operator_reduce_sum.cpp
    ${ASCENDC_TESTS_DIR}/reduce/reduce_mean/test_operator_reduce_mean.cpp
    ${ASCENDC_TESTS_DIR}/reduce/reduce_xor_sum/test_operator_reduce_xor_sum.cpp
    ${ASCENDC_TESTS_DIR}/index/arithprogression/test_operator_arithprogression.cpp
    ${ASCENDC_TESTS_DIR}/pad/broadcast/test_operator_broadcast_v220.cpp
    ${ASCENDC_TESTS_DIR}/filter/dropout/test_operator_dropout.cpp
    ${ASCENDC_TESTS_DIR}/pad/pad/test_operator_pad.cpp
    ${ASCENDC_TESTS_DIR}/select/selectwithbytesmask/test_operator_selectwithbytesmask.cpp
    ${ASCENDC_TESTS_DIR}/transpose/confusion_transpose/test_operator_confusion_transpose.cpp
    ${ASCENDC_TESTS_DIR}/math/acos/test_operator_acos.cpp
    ${ASCENDC_TESTS_DIR}/math/acosh/test_operator_acosh.cpp
    ${ASCENDC_TESTS_DIR}/math/asin/test_operator_asin.cpp
    ${ASCENDC_TESTS_DIR}/math/asinh/test_operator_asinh.cpp
    ${ASCENDC_TESTS_DIR}/math/atan/test_operator_atan.cpp
    ${ASCENDC_TESTS_DIR}/math/atanh/test_operator_atanh.cpp
    ${ASCENDC_TESTS_DIR}/math/axpy/test_operator_axpy.cpp
    ${ASCENDC_TESTS_DIR}/math/ceil/test_operator_ceil.cpp
    ${ASCENDC_TESTS_DIR}/math/clamp/test_operator_clamp.cpp
    ${ASCENDC_TESTS_DIR}/math/cos/test_operator_cos.cpp
    ${ASCENDC_TESTS_DIR}/math/cosh/test_operator_cosh.cpp
    ${ASCENDC_TESTS_DIR}/math/cumsum/test_operator_cumsum.cpp
    ${ASCENDC_TESTS_DIR}/math/digamma/test_operator_digamma.cpp
    ${ASCENDC_TESTS_DIR}/math/erf/test_operator_erf.cpp
    ${ASCENDC_TESTS_DIR}/math/erfc/test_operator_erfc.cpp
    ${ASCENDC_TESTS_DIR}/math/exp/test_operator_exp.cpp
    ${ASCENDC_TESTS_DIR}/math/floor/test_operator_floor.cpp
    ${ASCENDC_TESTS_DIR}/math/frac/test_operator_frac.cpp
    ${ASCENDC_TESTS_DIR}/math/log/test_operator_log.cpp
    ${ASCENDC_TESTS_DIR}/math/power/test_operator_power.cpp
    ${ASCENDC_TESTS_DIR}/math/round/test_operator_round.cpp
    ${ASCENDC_TESTS_DIR}/math/sign/test_operator_sign.cpp
    ${ASCENDC_TESTS_DIR}/math/sin/test_operator_sin.cpp
    ${ASCENDC_TESTS_DIR}/math/sinh/test_operator_sinh.cpp
    ${ASCENDC_TESTS_DIR}/math/tan/test_operator_tan.cpp
    ${ASCENDC_TESTS_DIR}/math/tanh/test_operator_tanh.cpp
    ${ASCENDC_TESTS_DIR}/math/xor/test_operator_xor.cpp
    ${ASCENDC_TESTS_DIR}/math/fmod/test_operator_fmod.cpp
    ${ASCENDC_TESTS_DIR}/math/trunc/test_operator_trunc.cpp
    ${ASCENDC_TESTS_DIR}/normalization/batchnorm/test_operator_batchnorm.cpp
    ${ASCENDC_TESTS_DIR}/normalization/deepnorm/test_operator_deepnorm.cpp
    ${ASCENDC_TESTS_DIR}/normalization/groupnorm/test_operator_groupnorm.cpp
    ${ASCENDC_TESTS_DIR}/normalization/layernorm/test_operator_layernorm.cpp
    # ${ASCENDC_TESTS_DIR}/normalization/layernorm/test_operator_layernormgrad.cpp
    ${ASCENDC_TESTS_DIR}/normalization/layernorm/test_operator_layernormgradbeta.cpp
    ${ASCENDC_TESTS_DIR}/normalization/rmsnorm/test_operator_rmsnorm.cpp
    ${ASCENDC_TESTS_DIR}/normalization/normalize/test_operator_normalize.cpp
    ${ASCENDC_TESTS_DIR}/normalization/welfordupdate/test_operator_welfordupdate.cpp
    ${ASCENDC_TESTS_DIR}/quantization/antiquant/test_ascend_antiquant_scalar.cpp
    ${ASCENDC_TESTS_DIR}/quantization/antiquant/test_ascend_antiquant_weight_scalar.cpp
    ${ASCENDC_TESTS_DIR}/quantization/antiquant/test_ascend_antiquant_weight.cpp
    ${ASCENDC_TESTS_DIR}/quantization/antiquant/test_ascend_antiquant.cpp
    ${ASCENDC_TESTS_DIR}/quantization/dequant/test_operator_dequant.cpp
    ${ASCENDC_TESTS_DIR}/quantization/quant/test_operator_quant.cpp
    ${ASCENDC_TESTS_DIR}/quantization/quant/test_operator_quant_per_channel.cpp
    ${ASCENDC_TESTS_DIR}/sort/topk/test_operator_topk.cpp
    ${ASCENDC_TESTS_DIR}/normalization/welfordfinalize/test_operator_welfordfinalize.cpp
    ${ASCENDC_TESTS_DIR}/utils/init_global_memory/test_operator_init_global_memory.cpp
    ${ASCENDC_TESTS_DIR}/normalization/layernormV2/test_operator_layernormV2.cpp
)

# ascend910B1 aic test cases
file(GLOB ASCENDC_TEST_ascend910B1_AIC_CASE_SRC_FILES
    ${ASCENDC_TESTS_DIR}/matmul/test_operator_matmul_v220.cpp
    ${ASCENDC_TESTS_DIR}/matmul/test_matmul_l0db.cpp
    ${ASCENDC_TESTS_DIR}/matmul/test_matmul_config.cpp
    ${ASCENDC_TESTS_DIR}/matmul/test_matmul_channel_split.cpp
    ${ASCENDC_TESTS_DIR}/matmul/test_matmul_triangular.cpp
    ${ASCENDC_TESTS_DIR}/matmul/cube_in_buffer/test_cube_in_buffer_normal.cpp
    ${ASCENDC_TESTS_DIR}/matmul/cube_in_buffer/test_cube_in_buffer_single_buffer.cpp
    ${ASCENDC_TESTS_DIR}/matmul/cube_in_buffer/test_cube_in_buffer_double_buffer.cpp
    ${ASCENDC_TESTS_DIR}/matmul/cube_in_buffer/test_cube_in_buffer_single_global_buffer.cpp
    ${ASCENDC_TESTS_DIR}/matmul/cube_in_buffer/test_cube_in_buffer_double_global_buffer.cpp
    ${ASCENDC_TESTS_DIR}/matmul/cube_in_buffer/test_cube_in_buffer_n_buffer.cpp
    ${ASCENDC_TESTS_DIR}/matmul/test_matmul_l0c_buffer.cpp
    ${ASCENDC_TESTS_DIR}/matmul/test_matmul_shape_info.cpp
    ${ASCENDC_TESTS_DIR}/matmul/test_matmul_shape_info_left.cpp
    ${ASCENDC_TESTS_DIR}/matmul/copy_cube_in/test_copy_cube_in_params.cpp
    ${ASCENDC_TESTS_DIR}/matmul/copy_cube_in/test_copy_cube_in_norm.cpp
    ${ASCENDC_TESTS_DIR}/matmul/copy_cube_in/test_copy_cube_in_mdl.cpp
    ${ASCENDC_TESTS_DIR}/matmul/iterator/test_k_loop_norm.cpp
    ${ASCENDC_TESTS_DIR}/matmul/iterator/test_k_loop_mdl.cpp
    ${ASCENDC_TESTS_DIR}/matmul/iterator/test_k_loop_mdl_reorder.cpp
    ${ASCENDC_TESTS_DIR}/matmul/iterator/test_k_loop_n_buffer.cpp
    ${ASCENDC_TESTS_DIR}/matmul/iterator/test_m_loop_norm.cpp
    ${ASCENDC_TESTS_DIR}/matmul/iterator/test_n_loop_norm.cpp
    ${ASCENDC_TESTS_DIR}/matmul/iterator/test_m_loop_basic.cpp
    ${ASCENDC_TESTS_DIR}/matmul/iterator/test_n_loop_basic.cpp
    ${ASCENDC_TESTS_DIR}/matmul/iterator/test_m_loop_mdl.cpp
    ${ASCENDC_TESTS_DIR}/matmul/iterator/test_n_loop_mdl.cpp
    ${ASCENDC_TESTS_DIR}/matmul/iterator/test_m_loop_mdl_outer_product.cpp
    ${ASCENDC_TESTS_DIR}/matmul/iterator/test_n_loop_mdl_outer_product.cpp
    ${ASCENDC_TESTS_DIR}/matmul/iterator/test_m_loop_n_buffer.cpp
    ${ASCENDC_TESTS_DIR}/matmul/iterator/test_batch_loop.cpp
    ${ASCENDC_TESTS_DIR}/matmul/iterator/test_batch_loop_single.cpp
    ${ASCENDC_TESTS_DIR}/matmul/iterator/test_batch_m_loop.cpp
    ${ASCENDC_TESTS_DIR}/matmul/iterator/test_batch_n_loop.cpp
    ${ASCENDC_TESTS_DIR}/matmul/iterator/test_matmul_iterator.cpp
    ${ASCENDC_TESTS_DIR}/matmul/load_buffer/test_matmul_load_to_l0a.cpp
    ${ASCENDC_TESTS_DIR}/matmul/load_buffer/test_matmul_load_to_l0b.cpp
    ${ASCENDC_TESTS_DIR}/matmul/load_buffer/test_matmul_mmad_compute.cpp
    ${ASCENDC_TESTS_DIR}/matmul/load_buffer/test_matmul_tbufpool_l0.cpp
    ${ASCENDC_TESTS_DIR}/matmul/bias/test_bias_c1_buffer.cpp
    ${ASCENDC_TESTS_DIR}/matmul/bias/test_bias_c2_buffer.cpp
    ${ASCENDC_TESTS_DIR}/matmul/bias/test_copy_bias_in.cpp
    # ${ASCENDC_TESTS_DIR}/matmul/bias/test_copy_bias_in_batch.cpp
    ${ASCENDC_TESTS_DIR}/matmul/scheduler/test_scheduler_mdl.cpp
    ${ASCENDC_TESTS_DIR}/matmul/scheduler/test_scheduler_special_mdl.cpp
    ${ASCENDC_TESTS_DIR}/matmul/scheduler/test_scheduler_norm.cpp
    ${ASCENDC_TESTS_DIR}/matmul/scheduler/test_scheduler_intrablock.cpp
    ${ASCENDC_TESTS_DIR}/matmul/scheduler/test_scheduler_norm_outer_product.cpp
    ${ASCENDC_TESTS_DIR}/matmul/scheduler/test_scheduler_mdl_outer_product.cpp
    ${ASCENDC_TESTS_DIR}/matmul/scheduler/test_scheduler_n_buffer.cpp
    #${ASCENDC_TESTS_DIR}/matmul/scheduler/bias_scheduler/test_bias_scheduler_batch.cpp
    ${ASCENDC_TESTS_DIR}/matmul/scheduler/bias_scheduler/test_bias_scheduler_v220.cpp
    ${ASCENDC_TESTS_DIR}/matmul/scheduler/batch_scheduler/test_batch_scheduler.cpp
    ${ASCENDC_TESTS_DIR}/matmul/scheduler/batch_scheduler/test_batch_scheduler_single.cpp
)

# ascend310B1 test cases
file(GLOB ASCENDC_TEST_ascend310B1_CASE_SRC_FILES
    ${ASCENDC_TESTS_DIR}/activation/softmax/test_operator_softmax_v300.cpp
    ${ASCENDC_TESTS_DIR}/matmul/test_operator_matmul_v300.cpp
    ${ASCENDC_TESTS_DIR}/math/xor/test_operator_xor.cpp
    ${ASCENDC_TESTS_DIR}/math/floor/test_operator_floor.cpp
    ${ASCENDC_TESTS_DIR}/matmul/scheduler/test_scheduler_norm.cpp
)

foreach(product_type ${PRODUCT_TYPE_LIST})
    add_executable(ascendc_utest_${product_type}
        ${ASCENDC_TESTS_DIR}/main_global.cpp
        $<$<STREQUAL:${product_type},ascend610>:${ASCENDC_TESTS_DIR}/common/tik_pv_wrapper.cpp>
        $<$<STREQUAL:${product_type},ascend310p>:${ASCENDC_TESTS_DIR}/common/tik_pv_wrapper.cpp>
        $<$<STREQUAL:${product_type},ascend910B1_AIC>:${ASCENDC_TESTS_DIR}/common/k3_pvwrap.cpp>
        $<$<STREQUAL:${product_type},ascend910B1_AIV>:${ASCENDC_TESTS_DIR}/common/k3_pvwrap.cpp>
        $<$<STREQUAL:${product_type},ascend310B1>:${ASCENDC_TESTS_DIR}/common/k3_pvwrap.cpp>
        ${ASCENDC_TEST_${product_type}_CASE_SRC_FILES}
    )

    # add soc version flags
    if(${product_type} STREQUAL "ascend610")
        target_compile_definitions(ascendc_utest_${product_type} PRIVATE
            UT_TEST
            __CCE_AICORE__=200
            __DAV_M200__
            __UT_CHIP_VER__=610
        )
        target_link_directories(ascendc_utest_${product_type} PRIVATE
            ${ASCEND_DEP_LIB_DIR}
            ${ASCEND_CANN_PACKAGE_PATH}/tools/tikicpulib/lib/Ascend610
            ${ASCENDC_SYS_DIR}/simulator/Ascend610/lib/
        )
    elseif(${product_type} STREQUAL "ascend310p")
        target_compile_definitions(ascendc_utest_${product_type} PRIVATE
            UT_TEST
            __CCE_AICORE__=200
            __DAV_M200__
            __UT_CHIP_VER__=710
        )
        target_link_directories(ascendc_utest_${product_type} PRIVATE
            ${ASCEND_DEP_LIB_DIR}
            ${ASCEND_CANN_PACKAGE_PATH}/tools/tikicpulib/lib/Ascend610/
            ${ASCENDC_SYS_DIR}/simulator/Ascend610/lib/
        )
    elseif(${product_type} STREQUAL "ascend910B1_AIC")
        target_compile_definitions(ascendc_utest_${product_type} PRIVATE
            UT_TEST
            __CCE_AICORE__=220
            __DAV_C220__
            __DAV_C220_CUBE__
        )
        target_link_directories(ascendc_utest_${product_type} PRIVATE
            ${ASCEND_DEP_LIB_DIR}
            ${ASCEND_CANN_PACKAGE_PATH}/tools/tikicpulib/lib/Ascend910B1/
            ${ASCENDC_SYS_DIR}/simulator/Ascend910B1/lib/
        )
    elseif(${product_type} STREQUAL "ascend910B1_AIV")
        target_compile_definitions(ascendc_utest_${product_type} PRIVATE
            UT_TEST
            __CCE_AICORE__=220
            __DAV_C220__
            __DAV_C220_VEC__
        )
        target_link_directories(ascendc_utest_${product_type} PRIVATE
            ${ASCEND_DEP_LIB_DIR}
            ${ASCEND_CANN_PACKAGE_PATH}/tools/tikicpulib/lib/Ascend910B1
            ${ASCENDC_SYS_DIR}/simulator/Ascend910B1/lib/
        )
    elseif(${product_type} STREQUAL "ascend310B1")
        target_compile_definitions(ascendc_utest_${product_type} PRIVATE
            UT_TEST
            __CCE_AICORE__=300
            __DAV_M300__
            __UT_CHIP_VER__=300
        )
        target_link_directories(ascendc_utest_${product_type} PRIVATE
            ${ASCEND_DEP_LIB_DIR}
            ${ASCEND_CANN_PACKAGE_PATH}/tools/tikicpulib/lib/Ascend310B1/
            ${ASCENDC_SYS_DIR}/simulator/Ascend310B1/lib/
        )
    endif()

    target_compile_definitions(ascendc_utest_${product_type} PRIVATE
        __CCE_KT_TEST__=1
        ASCENDC_CPU_DEBUG=1
        ASCENDC_OOM=1
    )

    target_include_directories(ascendc_utest_${product_type} PRIVATE
        ${ASCENDC_TEST_HEADER_FILES}
        ${ASCENDC_DEP_HEADER_DIR}
    )

    target_compile_options(ascendc_utest_${product_type} PRIVATE
        -fno-access-control
    )

    target_link_libraries(ascendc_utest_${product_type} PRIVATE
        $<BUILD_INTERFACE:intf_llt_pub>
        -Wl,--no-as-needed
        tikicpulib_npuchk
        tikicpulib_cceprint
        tikicpulib_stubreg
        tikcpp_debug
        $<$<STREQUAL:${product_type},ascend310p>:_pvmodel>
        $<$<STREQUAL:${product_type},ascend610>:_pvmodel>
        $<$<STREQUAL:${product_type},ascend910B1_AIV>:pem_davinci>
        $<$<STREQUAL:${product_type},ascend910B1_AIC>:pem_davinci>
        $<$<STREQUAL:${product_type},ascend310B1>:pem_davinci>
        ascendalog
        c_sec
        mmpa
        error_manager
        -Wl,--as-needed
    )

    run_llt_test(
        TARGET ascendc_utest_${product_type}
        TASK_NUM 1
    )
endforeach()


############################################tiling ut###################################
file(GLOB ASCENDC_TILING_TEST_SRC_FILES
    ${ASCENDC_TESTS_DIR}/tiling/*.cpp
)

file(GLOB ASCENDC_TILING_SRC_FILES
    ${ASCENDC_API_DIR}/impl/activation/*.cpp
    ${ASCENDC_API_DIR}/impl/activation/geglu/*.cpp
    ${ASCENDC_API_DIR}/impl/activation/gelu/*.cpp
    ${ASCENDC_API_DIR}/impl/activation/reglu/*.cpp
    ${ASCENDC_API_DIR}/impl/activation/sigmoid/*.cpp
    ${ASCENDC_API_DIR}/impl/activation/softmax/*.cpp
    ${ASCENDC_API_DIR}/impl/activation/swiglu/*.cpp
    ${ASCENDC_API_DIR}/impl/pad/broadcast/*.cpp
    ${ASCENDC_API_DIR}/impl/pad/pad/*.cpp
    ${ASCENDC_API_DIR}/impl/reduce/mean/*.cpp
    ${ASCENDC_API_DIR}/impl/reduce/sum/*.cpp
    ${ASCENDC_API_DIR}/impl/reduce/reduce_xor_sum/*.cpp
    ${ASCENDC_API_DIR}/impl/select/selectwithbytesmask/*.cpp
    ${ASCENDC_API_DIR}/impl/transpose/confusion_transpose/*.cpp
    ${ASCENDC_API_DIR}/impl/filter/dropout/*.cpp
    ${ASCENDC_API_DIR}/impl/index/arithprogression/*.cpp
    ${ASCENDC_API_DIR}/impl/math/acos/*.cpp
    ${ASCENDC_API_DIR}/impl/math/acosh/*.cpp
    ${ASCENDC_API_DIR}/impl/math/asin/*.cpp
    ${ASCENDC_API_DIR}/impl/math/asinh/*.cpp
    ${ASCENDC_API_DIR}/impl/math/atan/*.cpp
    ${ASCENDC_API_DIR}/impl/math/atanh/*.cpp
    ${ASCENDC_API_DIR}/impl/math/axpy/*.cpp
    ${ASCENDC_API_DIR}/impl/math/ceil/*.cpp
    ${ASCENDC_API_DIR}/impl/math/clamp/*.cpp
    ${ASCENDC_API_DIR}/impl/math/cos/*.cpp
    ${ASCENDC_API_DIR}/impl/math/cosh/*.cpp
    ${ASCENDC_API_DIR}/impl/math/cumsum/*.cpp
    ${ASCENDC_API_DIR}/impl/math/digamma/*.cpp
    ${ASCENDC_API_DIR}/impl/math/erf/*.cpp
    ${ASCENDC_API_DIR}/impl/math/erfc/*.cpp
    ${ASCENDC_API_DIR}/impl/math/exp/*.cpp
    ${ASCENDC_API_DIR}/impl/math/floor/*.cpp
    ${ASCENDC_API_DIR}/impl/math/frac/*.cpp
    ${ASCENDC_API_DIR}/impl/math/lgamma/*.cpp
    ${ASCENDC_API_DIR}/impl/math/log/*.cpp
    ${ASCENDC_API_DIR}/impl/math/power/*.cpp
    ${ASCENDC_API_DIR}/impl/math/round/*.cpp
    ${ASCENDC_API_DIR}/impl/math/sign/*.cpp
    ${ASCENDC_API_DIR}/impl/math/sin/*.cpp
    ${ASCENDC_API_DIR}/impl/math/sinh/*.cpp
    ${ASCENDC_API_DIR}/impl/math/tan/*.cpp
    ${ASCENDC_API_DIR}/impl/math/tanh/*.cpp
    ${ASCENDC_API_DIR}/impl/math/xor/*.cpp
    ${ASCENDC_API_DIR}/impl/math/fmod/*.cpp
    ${ASCENDC_API_DIR}/impl/math/trunc/*.cpp
    ${ASCENDC_API_DIR}/impl/matmul/tiling/*.cpp
    ${ASCENDC_API_DIR}/impl/normalization/batchnorm/*.cpp
    ${ASCENDC_API_DIR}/impl/normalization/deepnorm/*.cpp
    ${ASCENDC_API_DIR}/impl/normalization/groupnorm/*.cpp
    ${ASCENDC_API_DIR}/impl/normalization/layernorm/*.cpp
    ${ASCENDC_API_DIR}/impl/normalization/layernormgrad/*.cpp
    ${ASCENDC_API_DIR}/impl/normalization/normalize/*.cpp
    ${ASCENDC_API_DIR}/impl/normalization/welfordfinalize/*.cpp
    ${ASCENDC_API_DIR}/impl/normalization/rmsnorm/*.cpp
    ${ASCENDC_API_DIR}/impl/quantization/antiquant/*.cpp
    ${ASCENDC_API_DIR}/impl/quantization/dequant/*.cpp
    ${ASCENDC_API_DIR}/impl/quantization/quant/*.cpp
    ${ASCENDC_API_DIR}/impl/sort/topk/*.cpp
    ${ASCENDC_API_DIR}/impl/reduce/reduce_tiling.cpp
    ${ASCENDC_API_DIR}/impl/normalization/layernormV2/*.cpp
)

# ascendc_tiling_utest
foreach(product_type ${PRODUCT_TYPE_LIST})
    add_executable(ascendc_tiling_utest_${product_type}
        ${ASCENDC_TILING_SRC_FILES}
        ${ASCENDC_TILING_TEST_SRC_FILES}
        ${ASCENDC_TESTS_DIR}/common/platform_stub.cpp
        ${ASCENDC_TESTS_DIR}/tiling/main.cpp
        $<$<BOOL:${BUILD_OPEN_PROJECT}>:$<TARGET_OBJECTS:${ASCENDC_API_ADV_OBJ}>>
    )

    if(${product_type} STREQUAL "ascend610")
        target_compile_definitions(ascendc_tiling_utest_${product_type} PRIVATE
            UT_TEST
            __CCE_AICORE__=200
        )
    elseif(${product_type} STREQUAL "ascend310p")
        target_compile_definitions(ascendc_tiling_utest_${product_type} PRIVATE
            UT_TEST
            __CCE_AICORE__=200
        )
    elseif(${product_type} STREQUAL "ascend910B1_AIC")
        target_compile_definitions(ascendc_tiling_utest_${product_type} PRIVATE
            UT_TEST
            __CCE_AICORE__=220
        )
    elseif(${product_type} STREQUAL "ascend910B1_AIV")
        target_compile_definitions(ascendc_tiling_utest_${product_type} PRIVATE
            UT_TEST
            __CCE_AICORE__=220
        )
    elseif(${product_type} STREQUAL "ascend310B1")
        target_compile_definitions(ascendc_tiling_utest_${product_type} PRIVATE
            UT_TEST
            __CCE_AICORE__=300
        )
    elseif(${product_type} STREQUAL "ascend610Lite")
        target_compile_definitions(ascendc_utest_${product_type} PRIVATE
            UT_TEST
            __CCE_AICORE__=310
        )
    endif()

    target_include_directories(ascendc_tiling_utest_${product_type} PRIVATE
        ${ASCENDC_DEP_HEADER_DIR}
        ${ASCENDC_TEST_HEADER_FILES}
        ${ASCENDC_API_DIR}/lib/
        ${ASCENDC_API_DIR}/lib/activation/
        ${ASCENDC_API_DIR}/lib/filter/
        ${ASCENDC_API_DIR}/lib/index/
        ${ASCENDC_API_DIR}/lib/pad/
        ${ASCENDC_API_DIR}/lib/reduce/
        ${ASCENDC_API_DIR}/lib/select/
        ${ASCENDC_API_DIR}/lib/transpose/
        ${ASCENDC_API_DIR}/lib/matmul/
        ${ASCENDC_API_DIR}/lib/math/
        ${ASCENDC_API_DIR}/lib/normalization/
        ${ASCENDC_API_DIR}/lib/quantization/
        ${ASCENDC_API_DIR}/lib/sort/
        ${ASCENDC_TESTS_DIR}/common/
    )

    target_link_directories(ascendc_tiling_utest_${product_type} PRIVATE
        ${ASCEND_DEP_LIB_DIR}
    )

    target_link_libraries(ascendc_tiling_utest_${product_type} PRIVATE
        $<BUILD_INTERFACE:intf_llt_pub>
        platform
        -Wl,--no-as-needed
        ascend_protobuf
        ascendalog
        c_sec
        mmpa
        graph
        graph_base
        register
        error_manager
        -Wl,--as-needed
        dl
    )

    run_llt_test(
        TARGET ascendc_tiling_utest_${product_type}
        TASK_NUM 1
    )
endforeach()
